//app.js
App({
  onLaunch: function() {
    wx.getSystemInfo({
      success: res => {
        // console.log('手机信息res',res)
        let modelmes = res.model;
        this.globalData.phoneHeight = res.windowHeight
        if (modelmes.search('iPhone X') != -1) {
          that.globalData.isIphoneX = true
        }
        let height = res.screenHeight
        let width = res.screenWidth
        if (height / width >= 2) {
          that.globalData.fullPhone = true
        }
      }
    })
  },
  setWatcher(data, watch) { // 接收页面js中传过来的data对象和watch对象
    Object.keys(watch).forEach(v => { // 将watch对象内的key遍历
      this.observe(data, v, watch[v]) // 监听data内的v属性，传入watch内对应函数以调用
    })
  },
  /*
   * 监听属性，并执行监听函数
   */
  observe(obj, key, watchFun) {
    var oldValue = obj[key] // 给该属性设置默认值,即老值
    Object.defineProperty(obj, key, {
      configurable: true,
      enumerable: true,
      set: function(newValue) {
        watchFun(oldValue, newValue) // 赋值(set)时，调用对应函数
        oldValue = newValue
      },
      get: function() {
        return oldValue
      }
    })
  },
  globalData: {
    userInfo: null,
    login_state: false,
    demo_1: "123",
    phoneHeight: "",
    isIphoneX: false,
    fullPhone: false,
  }
})
